package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;

import model.User;

public class  UserDao implements IUserDao {
	private JdbcTemplate jdbcTemplate;
	public User getUser(String userName) {
		
			String sql = "SELECT * FROM cnpm.food WHERE name=" + userName;
			return jdbcTemplate.query(sql, new ResultSetExtractor<User>() {

				public User extractData(ResultSet rs) throws SQLException,
						DataAccessException {
					if (rs.next()) {
						User user = new User();
						user.setName(rs.getString("name"));
						user.setPassword(rs.getString("password"));
						user.setRole(rs.getString("role"));
						return user;
					}

					return null;
				}

			});
	}

}
